package com.jmi.chmtrace.back.Controller;


import com.alibaba.fastjson.JSONObject;
import com.jmi.chmtrace.back.Pojo.User;
import com.jmi.chmtrace.back.Service.UserService;
import com.jmi.chmtrace.back.utils.resUtil;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    UserService userService;
    @Resource
    resUtil resUtil;

    //TODO 登录功能实现，通过角色标识实现不同角色的登录
    //生产商标识：role = 1
    //运输商标识：role = 2
    //经销商标识：role = 3
    @PostMapping("/doLogin")
    @ResponseBody
    public JSONObject doLogin(@RequestBody User user ){
        //TODO 前端加密密码传输

        JSONObject response = new JSONObject();
        //检查参数
        if (ObjectUtils.isEmpty(user)) {
            return resUtil.standResNoData(400,"非法参数");
        }
        if (userService.UserLogin(user)) {

            return resUtil.SuccessMsg("登录成功");
        }else {
            return resUtil.standResNoData(400,"登录失败");
        }
    }
}
